$(function() {
				var $form_div = $("#dailyNursing_form div");
				winResize($form_div);
				$(window).resize(function(){//当调整浏览器窗口的大小时，发生 resize 事件
					winResize($form_div);
				});
				dateFormatter();
				loadTable();
				
})


var $form = $('#dailyNursing_form');
function  loadTable()
{	
	var columnsAll = new Array();
	columnsAll.push({field:'customerid',title:'ids',align:'center',hidden:true});
	
	columnsAll.push({field:'firstdate',title:'进店日期',width:80,align:'center'});
	columnsAll.push({field:'firstweight',title:'最初体重',width:50,align:'center'});
	columnsAll.push({field:'standardweight',title:'标准体重',width:50,align:'center'});
	columnsAll.push({field:'delweight',title:'应减斤数',width:50,align:'center'});
	columnsAll.push({field:'ddcount',title:'当月到<br/>店次数',width:35,align:'center'});
	/*columnsAll.push({field:'gjweight',title:'当月目标',width:100,align:'center',
		formatter: function(value,row,index)
		{	
			if(value!=null){ return  value;}
			else{return row.thismonthaim="0";}
		}
	});*/
	columnsAll.push({field:'gjweight',title:'当月实<br/>减斤数',width:50,align:'center',
		formatter: function(value,row,index)
		{	
			if(value!=null){ return  value;}
			else{return row.thismonthactualreduction="0";}
		}
	});
	//columnsAll.push({field:'yieldrateofthismonthaim',title:'当月目标达成率',width:100,align:'center'});
/*	columnsAll.push({field:'customertype',title:'是否达标',width:30,align:'center',
		formatter: function(value,row,index)
		{	
			if(value=="2")
			{
				return  '<span style="color:#ff954e;">是</span>';
			}else
			{
				return  '否';
			}
			
		}
	});*/
	/*columnsAll.push({field:'weightqk01',title:'weightqk01',align:'center',hidden:true});
	columnsAll.push({field:'weightqk02',title:'weightqk02',align:'center',hidden:true});
	columnsAll.push({field:'weightqk03',title:'weightqk03',align:'center',hidden:true});
	columnsAll.push({field:'weightqk04',title:'weightqk04',align:'center',hidden:true});
	columnsAll.push({field:'weightqk05',title:'weightqk05',align:'center',hidden:true});
	columnsAll.push({field:'weightqk06',title:'weightqk06',align:'center',hidden:true});
	columnsAll.push({field:'weightqk07',title:'weightqk07',align:'center',hidden:true});
	columnsAll.push({field:'weightqk08',title:'weightqk08',align:'center',hidden:true});
	columnsAll.push({field:'weightqk09',title:'weightqk09',align:'center',hidden:true});
	columnsAll.push({field:'weightqk10',title:'weightqk10',align:'center',hidden:true});
	columnsAll.push({field:'weightqk11',title:'weightqk11',align:'center',hidden:true});
	columnsAll.push({field:'weightqk12',title:'weightqk12',align:'center',hidden:true});
	columnsAll.push({field:'weightqk13',title:'weightqk13',align:'center',hidden:true});
	columnsAll.push({field:'weightqk14',title:'weightqk14',align:'center',hidden:true});
	columnsAll.push({field:'weightqk15',title:'weightqk15',align:'center',hidden:true});
	columnsAll.push({field:'weightqk16',title:'weightqk16',align:'center',hidden:true});
	columnsAll.push({field:'weightqk17',title:'weightqk17',align:'center',hidden:true});
	columnsAll.push({field:'weightqk18',title:'weightqk18',align:'center',hidden:true});
	columnsAll.push({field:'weightqk19',title:'weightqk19',align:'center',hidden:true});
	columnsAll.push({field:'weightqk20',title:'weightqk20',align:'center',hidden:true});
	columnsAll.push({field:'weightqk21',title:'weightqk21',align:'center',hidden:true});
	columnsAll.push({field:'weightqk22',title:'weightqk22',align:'center',hidden:true});
	columnsAll.push({field:'weightqk23',title:'weightqk23',align:'center',hidden:true});
	columnsAll.push({field:'weightqk24',title:'weightqk24',align:'center',hidden:true});
	columnsAll.push({field:'weightqk25',title:'weightqk25',align:'center',hidden:true});
	columnsAll.push({field:'weightqk26',title:'weightqk26',align:'center',hidden:true});
	columnsAll.push({field:'weightqk27',title:'weightqk27',align:'center',hidden:true});
	columnsAll.push({field:'weightqk28',title:'weightqk28',align:'center',hidden:true});
	columnsAll.push({field:'weightqk29',title:'weightqk29',align:'center',hidden:true});
	columnsAll.push({field:'weightqk30',title:'weightqk30',align:'center',hidden:true});
	columnsAll.push({field:'weightqk31',title:'weightqk31',align:'center',hidden:true});
	columnsAll.push({field:'weight01',title:1,width:50,align:'center',formatter: function(value,row,index){	
			if(value !=null)
			{
				if(value == '0'){
					
					return '';
				}else{
					if(row.weightqk01!=null && row.weightqk01!=""){
						
						return   "<span  style='color:"+row.weightqk01+"'>" + value + "<span>";
					}else{
						return   value ;
					}
					
				}
			}
		}
	});
	columnsAll.push({field:'weight02',title:2,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk02!=null && row.weightqk02!=""){
					return   "<span  style='color:"+row.weightqk02+"'>" + value + "<span>";
				}else{
					return   value ;
				}
				
			}
		}
	}
});
	columnsAll.push({field:'weight03',title:3,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk02!=null && row.weightqk02!=""){
					return   "<span  style='color:"+row.weightqk03+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight04',title:4,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk04!=null && row.weightqk04!=""){
					return   "<span  style='color:"+row.weightqk04+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight05',title:5,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk05!=null && row.weightqk05!=""){
					return   "<span  style='color:"+row.weightqk05+"'>" + value + "<span>";
					if(row.weightqk05>0)
					{
						return   "<span  style='color:green'>" + value + "<span>";
					}
					else if(row.weightqk05==0)
					{	
						return   "<span  style='color:#00CCFF'>" + value + "<span>";
					}
					else if(row.weightqk05<0)
					{
						return   "<span  style='color:red'>" + value + "<span>";
					}else
					{
						return   value ;
					}
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight06',title:6,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk06!=null && row.weightqk06!=""){
					
						return   "<span  style='color:"+row.weightqk06+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight07',title:7,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk07!=null && row.weightqk07!=""){
					return   "<span  style='color:"+row.weightqk07+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight08',title:8,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk08!=null && row.weightqk08!=""){
					return   "<span  style='color:"+row.weightqk08+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight09',title:9,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk09!=null && row.weightqk09!=""){
					return   "<span  style='color:"+row.weightqk09+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight10',title:10,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk10!=null && row.weightqk10!=""){
					
						return   "<span  style='color:"+row.weightqk10+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight11',title:11,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk11!=null && row.weightqk11!=""){
					return   "<span  style='color:"+row.weightqk11+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight12',title:12,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk12!=null && row.weightqk12!=""){
					return   "<span  style='color:"+row.weightqk12+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight13',title:13,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk13!=null && row.weightqk13!=""){
					return   "<span  style='color:"+row.weightqk13+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight14',title:14,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk14!=null && row.weightqk14!=""){
					return   "<span  style='color:"+row.weightqk14+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight15',title:15,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk15!=null && row.weightqk15!=""){
					return   "<span  style='color:"+row.weightqk15+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight16',title:16,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk16!=null && row.weightqk16!=""){
					return   "<span  style='color:"+row.weightqk16+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight17',title:17,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk17!=null && row.weightqk17!=""){
					return   "<span  style='color:"+row.weightqk17+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight18',title:18,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk18!=null && row.weightqk18!=""){
					return   "<span  style='color:"+row.weightqk18+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight19',title:19,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk19!=null && row.weightqk19!=""){
					return   "<span  style='color:"+row.weightqk19+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight20',title:20,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk20!=null && row.weightqk20!=""){
					return   "<span  style='color:"+row.weightqk20+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight21',title:21,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk21!=null && row.weightqk21!=""){
					return   "<span  style='color:"+row.weightqk21+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight22',title:22,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk22!=null && row.weightqk22!=""){
					return   "<span  style='color:"+row.weightqk22+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight23',title:23,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk23!=null && row.weightqk23!=""){
					return   "<span  style='color:"+row.weightqk23+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight24',title:24,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk24!=null && row.weightqk24!=""){
					return   "<span  style='color:"+row.weightqk24+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight25',title:25,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk25!=null && row.weightqk25!=""){
					return   "<span  style='color:"+row.weightqk25+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight26',title:26,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk26!=null && row.weightqk26!=""){
					return   "<span  style='color:"+row.weightqk26+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight27',title:27,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk27!=null && row.weightqk27!=""){
					return   "<span  style='color:"+row.weightqk27+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight28',title:28,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk28!=null && row.weightqk28!=""){
					return   "<span  style='color:"+row.weightqk28+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight29',title:29,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk29!=null && row.weightqk29!=""){
					return   "<span  style='color:"+row.weightqk29+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight30',title:30,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk30!=null && row.weightqk30!=""){
					return   "<span  style='color:"+row.weightqk30+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});
	columnsAll.push({field:'weight31',title:31,width:50,align:'center',formatter: function(value,row,index){	
		if(value !=null)
		{
			if(value == '0'){
				
				return '';
			}else{
				if(row.weightqk31!=null && row.weightqk31!=""){
					return   "<span  style='color:"+row.weightqk31+"'>" + value + "<span>";
				}else{
					return   value ;
				}
			}
		}
	}
});*/

	
	for(var n=1;n<32;n++){
		var nstr = n;
		var nstr2 = n-1;
		if(n<10){
			nstr= '0'+n;
		}
		
		
		columnsAll.push({field:'weight'+nstr,title:n,width:50,align:'center',formatter: function(value,row,index){	
			/*if(value !=null){
				return  value;
			}*/
			
			var nn=0;
			nn=this.title;
			if(nn<10){
				nstr= '0'+nn;
			}
			else
				nstr= nn;
			
				var isdc='weightqk'+nstr;
				
				if(value !=null)
				{
					
					if(value == '0'){
						
						return '';
					}else{
						
						
						if(row[isdc]!=null && row[isdc]!=""){
							
							return   "<span  style='color:"+row[isdc]+"'>" + value + "<span>";
						}
						else{
							return   value ;
						}
					}
					
					
				}
			}
		});
	}
	
	columnsAll.push({field:'chargepersion',title:'负责人',width:100,align:'center'});
	columnsAll.push({field:'organname',title:'机构名称',width:100,align:'center'});
	/*columnsAll.push({field:'customername',title:'姓名',width:100,align:'center',
		formatter: function(value,row,index)
		{	var ids = row.cusids;
			if(value==null)
			{
				return  row.cusname=" ";
			}
			else
			{
				return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
			}
		}
	});*/
	//columnsAll.push({field:'phone',title:'手机',width:100,align:'center'});
	columnsAll.push({field:'hybh',title:'会员编号',width:100,align:'center'});
	$('#dailyNursing_datagrid').datagrid({
		cls: "theme-datagrid",
		  singleSelect:true,  
		  rownumbers: true,
		  toolbar: '#tb',
		  frozenColumns:[[
							{field:'customername',title:'姓名',width:50,align:'center',
								formatter: function(value,row,index)
								{	var ids = row.customerid;
								var customertype = row.customertype;
									if(value==null)
									{
										return  row.cusname=" ";
									}
									else
									{
										if(customertype == "2"){
											return '<a href="#" style="color: green;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
										}else{
											return '<a href="#" style="color: blue;" class="button-edit" onclick="lookCustomerInfo(\'' + ids + '\')">' + value + '</a>';
										}
										
									}
								}
							}
		        	]],
		  columns:[columnsAll],
		  url: "dailyNursing/getDailyNursingInfo",
		  queryParams: sy.serializeObject($form),
//		  showFooter:true, 
//		  footer:footer,
		 /* onLoadSuccess: function (data) {
           //合计
		   heji();
          },*/
	});
}
function  heji()
{	
		 var rows = $('#dailyNursing_datagrid').datagrid('getRows');
	
         for(var i=1;i<9;i++)
         {
        	 $('#dailyNursing_datagrid').datagrid('mergeCells',{
     			index: rows.length - i,
     			field: 'organname',
     			colspan:9 
     		});
         }
	
}

function searchFrom(){
	$('#dailyNursing_datagrid').datagrid('load',sy.serializeObject($form));
}

function  dateFormatter(){
	$('#dailyNursing_datebox').datebox({
	       //显示日趋选择对象后再触发弹出月份层的事件，初始化时没有生成月份层
	       onShowPanel: function () {
	          //触发click事件弹出月份层
	          span.trigger('click'); 
	          if (!tds)
	            //延时触发获取月份对象，因为上面的事件触发和对象生成有时间间隔
	            setTimeout(function() { 
	                tds = p.find('div.calendar-menu-month-inner td');
	                tds.click(function(e) {
	                   //禁止冒泡执行easyui给月份绑定的事件
	                   e.stopPropagation(); 
	                   //得到年份
	                   var year = /\d{4}/.exec(span.html())[0] ,
	                   //月份
	                   //之前是这样的month = parseInt($(this).attr('abbr'), 10) + 1; 
	                   month = parseInt($(this).attr('abbr'), 10);  

				         //隐藏日期对象                     
				         $('#dailyNursing_datebox').datebox('hidePanel').datebox('setValue', year + '-' + month); 
	                 });
	             }, 0);
	        },
	            //配置parser，返回选择的日期
	            parser: function (s) {
	                if (!s) return new Date();
	                var arr = s.split('-');
	                return new Date(parseInt(arr[0], 10), parseInt(arr[1], 10) - 1, 1);
	            },
	            //配置formatter，只返回年月 之前是这样的d.getFullYear() + '-' +(d.getMonth()); 
	            formatter: function (d) { 
	                var currentMonth = (d.getMonth()+1);
	                var currentMonthStr = currentMonth < 10 ? ('0' + currentMonth) : (currentMonth + '');
	                return d.getFullYear() + '-' + currentMonthStr; 
	            }
	        });

	        //日期选择对象
	        var p = $('#dailyNursing_datebox').datebox('panel'), 
	        //日期选择对象中月份
	        tds = false, 
	        //显示月份层的触发控件
	        span = p.find('span.calendar-text'); 
	        var curr_time = new Date();

	        //设置前当月
	        $("#dailyNursing_datebox").datebox("setValue", myformatter(curr_time));
    
 
}
//格式化日期
function myformatter(date) {
    //获取年份
    var y = date.getFullYear();
    //获取月份
    var m = date.getMonth() + 1;
    return y + '-' + m;
}


